package com.example.crm.repository;

import com.example.crm.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


/**
 * @author lenovo
 */
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
    /**
     * 按用户名字模糊查询
     * @param useName
     * @return
     */
    public List<User> findByUsrNameLike(String useName);

    /**
     * 按角色查询用户并分页
     * @param roleId
     * @param pageable
     * @return
     */
    @Query("select u from User u where u.usrRoleId=?1")
    public Page<User> findPageByUsrRoleId(Long roleId, Pageable pageable);

    /**
     * 动态查询的复杂分页
     * @param userSpecification
     * @param pageable
     * @return
     */
    @Override
    Page<User> findAll(Specification<User> userSpecification, Pageable pageable);
}